const fs = require("fs");
const path = require("path");
const filePath = path.join(__dirname, "test.txt");
const toPath = path.join(__dirname, "to.txt");
//创建可读流
let readStream = fs.createReadStream(filePath);

//创建可写流
let writeStream = fs.createWriteStream(toPath);


//通过流的方式把数据进行写入
readStream.pipe(writeStream);

console.log(fs.statSync(toPath).mode);
let fileObj = fs.statSync(filePath);
//把filePath文件的权限也赋值给了toPath

fs.chmodSync(toPath, fileObj.mode);
console.log(fs.statSync(toPath).mode);
console.log(fs.statSync(filePath).mode);

